﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MShop.Core.Domain;

namespace MShop.Core.DataAccess
{
    public class PayPluginDao:CommonDao<PayPlugin>,IPayPluginDao
    {
        public PayPluginDao(IObjectContextProvider provider)
            : base(provider)
        {
             
        }

        public IPayModel GetPayModel(int id)
        {
            string paytype = this.GetById(id).PayType;
            try
            {
                return (IPayModel)System.Activator.CreateInstance(Type.GetType(paytype));
            }
            catch
            {
                return new CodPayModel();
            }
        }


        #region IPayPluginDao Members


        public PayPlugin GetPayModel(Type ptype)
        {
            foreach (var item in this.GetAll())
            {
                Type type=Type.GetType(item.PayType);
                //object obj=  System.Activator.CreateInstance(type);
                if (ptype == type)
                {
                    return item;
                }
            }
            return null;
        }

        #endregion
    }
}